package pack.findthewords;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

public class HowTo extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.howto);

	// On small screens, force portrait layout
	if (((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL)
	    || ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL)) {
	    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}

	final TextView tipTv=(TextView) findViewById(R.id.info_tip);
	int r=Utils.getRandForTip();
	final String urlTip=Utils.LOOKUP_TIPS_URLS[r];
	tipTv.setText(getResources().getString(Utils.LOOKUP_TIPS[r]));
	tipTv.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		Intent i=new Intent(Intent.ACTION_VIEW, Uri.parse(urlTip));
		startActivity(i);
	    }
	});
    }

    public void back(View v) {
	finish();
    }

    /*
     * Options menu
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
	MenuInflater inflater=getMenuInflater();
	inflater.inflate(R.menu.opt_menu_gen, menu);
	return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	    case R.id.opt_vote:
		Intent ii=new Intent(Intent.ACTION_VIEW, Uri.parse(Utils.MARKET_URL));
		startActivity(ii);
		return true;
	    case R.id.opt_back:
		finish();
		return true;
		/*
		 * case R.id.opt_adfree: Intent iii=new Intent(Intent.ACTION_VIEW,
		 * Uri.parse(Utils.MARKET_URL_NOADS)); startActivity(iii); return true; case
		 * R.id.opt_info: Intent iiii=new Intent(HowTo.this, Info.class);
		 * startActivity(iiii); return true;
		 */
	    default:
		return super.onOptionsItemSelected(item);
	}
    }

}
